<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>数组at</title>
</head>

<body>
    <script>
        /**
         *  at返回数组指定索引位置的值
            

        */

        // at返回数组指定索引位置的值
        const colors = ["red", "green", "blue"];
        let item = colors.at(-1)
        console.log(item); // blue

        // 在非数组对象上调用
        const arrayLike = {
            length: 2,
            0: "a",
            1: "b",
        };
        console.log(Array.prototype.at.call(arrayLike, -1)); // b
    </script>
</body>

</html>